using System;
using System.Collections.Generic;
using System.Text;

using phorm;
using phorm.application;
using phorm.config;
using phorm.database.core;
using phorm.database.mssql;
using phorm.model;
using phorm.utils;

namespace TestPhorm
{
    /// <summary>
    /// Second test case:
    /// Sets up config parameters, database, and tables. Creates a few objects.
    /// Tests saving objects. Tests initWithId of an object.
    /// </summary>
    class Test2
    {
        /// <summary>
        /// Runs the test case.
        /// </summary>
        public static void runTest()
        {
            PhormParams phormParams = new PhormParams();
            phormParams.dbType = "mssql";
            phormParams.dbHost = "localhost";
            phormParams.dbUsername = "sa";
            phormParams.dbPassword = "password";
            phormParams.dbName = "bookStore";
            PhormConfig.phormParams = phormParams;

            ApplicationMSSQL.setup();

            Author author = new Author();
            author.AuthorFirstName.value = "Pogo";
            author.Password.value = "testpass";
            author.save();
            author.save();

            Publisher publisher = new Publisher();
            publisher.PublisherName.value = "Pogo Publishing House";
            publisher.save();

            Book book1 = new Book();
            book1.BookName.value = "Pogo and the Sea-Goats: An Autobiography";
            book1.ISBN.value = 12349592;
            book1.Price.value = 59.95;
            book1.Authors.add(author);
            book1.PublisherID.add(publisher);
            book1.save();

            Book book3 = new Book();
            book3.initWithId(book1.BookID.value);

            Console.Write("\nPress any key to continue...");
            Console.ReadKey();
        }
    }
}
